package com.kld.yqyj.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kld.common.annotation.Log;
import com.kld.common.annotation.RepeatSubmit;
import com.kld.common.core.controller.BaseController;
import com.kld.common.core.domain.PageQuery;
import com.kld.common.core.domain.R;
import com.kld.common.core.page.TableDataInfo;
import com.kld.common.core.validate.AddGroup;
import com.kld.common.core.validate.EditGroup;
import com.kld.common.core.validate.QueryGroup;
import com.kld.common.enums.BusinessType;
import com.kld.common.utils.poi.ExcelUtil;
import com.kld.yqyj.domain.bo.TDzKfdyCurInforBo;
import com.kld.yqyj.domain.vo.TDzKfdyCurInforVo;
import com.kld.yqyj.service.ITDzKfdyCurInforService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 开发单元基础信息Controller
 *
 * @author bw
 * @date 2024-05-15
 */
@Validated
@Api(value = "开发单元基础信息控制器", tags = {"开发单元基础信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/yqyj/dzKfdyCurInfor")
public class TDzKfdyCurInforController extends BaseController {

    private final ITDzKfdyCurInforService iTDzKfdyCurInforService;

    /**
     * 查询开发单元基础信息列表
     */
    @ApiOperation("查询开发单元基础信息列表")
    @SaCheckPermission("yqyj:dzKfdyCurInfor:list")
    @GetMapping("/list")
    public TableDataInfo<TDzKfdyCurInforVo> list(@Validated(QueryGroup.class) TDzKfdyCurInforBo bo, PageQuery pageQuery) {
        return iTDzKfdyCurInforService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出开发单元基础信息列表
     */
    @ApiOperation("导出开发单元基础信息列表")
    @SaCheckPermission("yqyj:dzKfdyCurInfor:export")
    @Log(title = "开发单元基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TDzKfdyCurInforBo bo, HttpServletResponse response) {
        List<TDzKfdyCurInforVo> list = iTDzKfdyCurInforService.queryList(bo);
        ExcelUtil.exportExcel(list, "开发单元基础信息", TDzKfdyCurInforVo.class, response);
    }

    /**
     * 获取开发单元基础信息详细信息
     */
    @ApiOperation("获取开发单元基础信息详细信息")
    @SaCheckPermission("yqyj:dzKfdyCurInfor:query")
    @GetMapping("/{geoId}")
    public R<TDzKfdyCurInforVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("geoId") String geoId) {
        return R.ok(iTDzKfdyCurInforService.queryById(geoId));
    }

    /**
     * 新增开发单元基础信息
     */
    @ApiOperation("新增开发单元基础信息")
    @SaCheckPermission("yqyj:dzKfdyCurInfor:add")
    @Log(title = "开发单元基础信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TDzKfdyCurInforBo bo) {
        return toAjax(iTDzKfdyCurInforService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改开发单元基础信息
     */
    @ApiOperation("修改开发单元基础信息")
    @SaCheckPermission("yqyj:dzKfdyCurInfor:edit")
    @Log(title = "开发单元基础信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TDzKfdyCurInforBo bo) {
        return toAjax(iTDzKfdyCurInforService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除开发单元基础信息
     */
    @ApiOperation("删除开发单元基础信息")
    @SaCheckPermission("yqyj:dzKfdyCurInfor:remove")
    @Log(title = "开发单元基础信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{geoIds}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] geoIds) {
        return toAjax(iTDzKfdyCurInforService.deleteWithValidByIds(Arrays.asList(geoIds), true) ? 1 : 0);
    }
}
